﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DAL;
using System.Configuration;

namespace TestProject2
{
    [TestClass]
    public class UnitTest1
    {
        string conString = null;

        [TestInitialize]
        public void Can_Get_ConString_From_AppConfig()
        {
            conString = ConfigurationManager.ConnectionStrings["linq"].ConnectionString;
            Assert.IsNotNull(conString);
        }

        [TestMethod]
        public void Can_Get_All_Clientes()
        {
            //Asing
            Model m = new Model(conString);

            //Action
            var clientes = m.GetClientes();

            //Assert
            Assert.IsTrue(clientes.Count > 0);

        }

        [TestMethod]
        public void Can_Find_A_Clientes()
        {
            //Asing
            Model m = new Model(conString);

            //Action
            var clientes = m.GetClientes("1");

            //Assert
            Assert.IsTrue(clientes.Count > 0);
        }

        [TestMethod]
        public void Can_Insert_A_Clientes()
        {
            //Asing
            Cliente c = new Cliente();
            c.Apellido = string.Concat("Ape_", DateTime.Today.ToString());
            c.Nombre = string.Concat("Nom_", DateTime.Today.ToString());
           
            Model m = new Model(conString);
            
            //Action
            bool result = m.InsertCliente(c);

            //Assert
            Assert.IsTrue(result);
        }

        [TestMethod]
        public void Can_Delete_A_Cliente_By_Id()
        {
            //Asing
            int id = 1;
            Model m = new Model(conString);

            //Action
            bool result = m.DeleteCliente(id);

            //Assert
            Assert.IsTrue(result);
        }

         [TestMethod]
        public void Can_Delete_A_Cliente_By_Client()
        {
            //Asing
            Cliente c = new Cliente();
            c.ClienteID = 5;
            Model m = new Model(conString);

            //Action
            bool result = m.DeleteCliente(c);

            //Assert
            Assert.IsTrue(result);
        }
    }
}
